package com.company.cloud.common.mq.redis.client.consumer;

import org.springframework.util.StringUtils;

import com.company.cloud.common.mq.redis.client.consumer.annotation.MQRedisConsumer;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MQConsumerModel {

	/**MQ Topic*/
	private String topic;
	
	/**消费者分组*/
	private String group;
	
	/**消费者*/
	private String consumer;
	
	/**批量读取数量*/
	private long count=1L;
	
	/**阻塞读取时间秒 (-1不阻塞,0一直阻塞,1)*/
	private long blockTimeout=-1L;
	
	/**读取后是否确认*/
	private boolean isAuctAck=false;
	
	/**多线程处理过期时间(秒),大于0多线程处理,其它非多线程处理*/
	private long runTimeout=0L;

	public MQConsumerModel() {

	}

	public MQConsumerModel(MQRedisConsumer mqConsumer) {
		this.topic=mqConsumer.topic();
		this.group=mqConsumer.group();
		if(StringUtils.isEmpty(mqConsumer.consumer())) {
			this.consumer=IdUtil.fastSimpleUUID();
		}else {
			this.consumer=mqConsumer.consumer();
		}
		
		if(mqConsumer.count()<=0) {
			this.count=1L;
		}else if(mqConsumer.count()>500) {
			this.count=500L;
		}else {
			this.count=mqConsumer.count();
		}
		this.blockTimeout=mqConsumer.blockTimeout()<=0?0:mqConsumer.blockTimeout();
		
		this.isAuctAck=mqConsumer.autoAck();
		
		this.runTimeout=mqConsumer.runTimeout()<=0?0:mqConsumer.runTimeout();
	}
	
	@Override
	public String toString() {
		return StrUtil.format("[topic={},group={},consumer={},count={},blockTimeout={},isAuctAck={},runTimeout={}]",
				this.topic,this.group,this.consumer,this.count,this.blockTimeout,this.isAuctAck,this.runTimeout);
	}

}
